#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct stu_node
{
    int age;
    char name[64];
};
struct link_node
{
    struct stu_node data;
    struct link_node *next;
};
//定义一个链表头节点
static struct link_node head;
//头插法插入，参数为新插入的节点信息
int insert_head(struct stu_node *data)
{
    struct link_node *newnode = malloc(sizeof(struct link_node));
    if(newnode == NULL)
    {
        printf("malloc failed");
        return -1;
    }
    newnode->data = *data;
    newnode->next = head.next;
    head.next = newnode;
}
//遍历输出节点的信息
void print_list()
{
    struct link_node *p = &head;
    while(p->next != NULL)
    {
        p = p->next;
        printf("age = %d, name = %s\n", p->data.age, p->data.name);
    }
}
int main()
{
    head.next = NULL;
    //定义新的节点并赋值
    struct stu_node data1 = {18, "cxy"};
    struct stu_node data2 = {19, "lxy"};
    //调用插入方法
    insert_head(&data1);
    insert_head(&data2);    
    //遍历输出
    print_list();
}
